<template>
    <a-modal
      :maskClosable="false"
      :keyboard="false"
      :title="title"
      :width="width"
      :visible="visible"
      @ok="handleOk"
      @cancel="handleCancel"
      :destroyOnClose="true"
      :cancelText="$t('m.common.button.close')">

    <a-spin :spinning="spinning != 0">
      <a-form :form="form"
              layout="horizontal"
              :hideRequiredMark="false"
              style="">
        <a-row>
          <a-col>
            <a-form-item :label="$t('m.common.label.name')" :label-col="labelCol" :wrapper-col="wrapperCol">
              <a-input
                :disabled="disabledRules.name"
                :placeholder="$t('m.common.tip.name_verify')"
                type="text"
                v-decorator="['name', validatorRules.name]"
              />
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-spin>
    </a-modal>
</template>

<script>

  import {FormMixin} from '@/mixins/FormMixin'
  import YchConstant from "@/api/YchConstant";
  import { getAction, httpAction,uploadAction,deleteAction } from '@/api/manage'

  export default {
    name: 'SysCollectFormModal',
    mixins: [FormMixin],
    components: {
    },
    data() {
      return {
        title: this.$t('m.common.title.add'),
        width:'400px',
        labelCol: { span: 3 },
        wrapperCol: { span: 21 },
        visible: false,

        validatorRules: {
          name: {
            rules: []
          }
        },
        disabledRules: {
          name: false
        },
        url: {
          queryById: YchConstant.PREFIX_SYSTEM +'/collection/queryById',
          add: YchConstant.PREFIX_SYSTEM +"/collection/add",
          edit: YchConstant.PREFIX_SYSTEM +"/collection/edit",
        },

      }
    },
    methods: {
      addCollect (model) {
        this.title = this.$t("m.common.title.add")
        this.visible = true
        this.model=model
      },
      edit (id) {
        this.title = this.$t("m.common.title.update")
        this.visible = true
        this.detail(id)
      },
      detail (id) {
        this.visible = true
        if (!this.url.queryById) {
          this.messageUtil.error('请设置url.queryById属性!')
          return
        }
        this.spinning++
        getAction(this.url.queryById, { id: id }).then((res) => {
          if (res.success) {
            this.initFormData(res.result)
          } else {
            this.messageUtil.warning(res.message)
          }
        }).finally(() => {
          this.spinning--
        })
        if (this.subTableConfig) {
          Object.keys(this.subTableConfig).forEach(key => {
            this.detailSubTableData(key, this.subTableConfig[key], id)
          })
        }
      },
      handleOk () {
        this.save()
      },
      handleCancel () {
        this.visible = false
      },

    }
  }
</script>
